Imports System.Drawing.Printing

Public Class FrMain
    Dim count As Integer = 0
    Private Sub TransactionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransactionsToolStripMenuItem.Click
        FrTransactions.Show()
    End Sub

    Private Sub AccessManagementToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AccessManagementToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgUser.ShowDialog()
        End If
    End Sub



    Private Sub CardManagementToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CardManagementToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgCard.ShowDialog()
        End If
    End Sub

    Private Sub QuarterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuarterToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgQuarter.ShowDialog()
        End If
    End Sub

    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
        'If LoginForm.admin Then
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgEmployee.setActionName("New")
            dlgEmployee.ShowDialog()
        End If
        'End If
    End Sub

    Private Sub ViewEmployeeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewEmployeeToolStripMenuItem.Click
        'If LoginForm.admin Then
        If Me.AdmintratorToolStripMenuItem.Visible Then
            If dlgFindEmployee.ShowDialog() = Windows.Forms.DialogResult.OK Then
                dlgEmployee.EmployeeID = dlgFindEmployee.employeeID
                dlgEmployee.setActionName("Update")
                dlgEmployee.ShowDialog()
            End If
        End If
        'End If
    End Sub
    
    Private Sub FrMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'If My.Settings.PrinterName.Length > 0 Then
        '    dlgPrint.PrinterSettings.PrinterName = My.Settings.PrinterName
        'End If
        'MainMenu.Items("TransactionsToolStripMenuItem").Visible = False
        'MainMenu.Items("AdmintratorToolStripMenuItem").Visible = False
        'MainMenu.Items("ReportsToolStripMenuItem").Visible = False
        AccessManagementToolStripMenuItem.Visible = False

        Me.LoginToolStripMenuItem_Click(sender, e)
        'ListBar1.Groups.Add("Welcome")
        'For i As Int16 = 0 To MainMenu.Items.Count - 1
        '    ListBar1.Groups.Add(MainMenu.Items(i).Text)

        'Next
        'Dim subItems(3) As ListBarItem
        'For item As Int16 = 0 To 3
        '    subItems(item) = New ListBarItem(String.Format("Test Item {0}", item + 1)) ', item + 1, String.Format("Tooltip text for test item {0}", item + 1))

        'Next
        'Dim group = New ListBarGroup("Group", subItems)
        'ListBar1.Groups.Add(group)

    End Sub


    Private Sub CouponMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CouponMenuItem.Click
        dlgCoupon.ShowDialog()
    End Sub




    'Private Sub TestPrintSetupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    ' Make a PrintDocument and attach it to 
    '    ' the Print dialog.
    '    Try
    '        dlgPrint.Document = PreparePrintDocument()
    '        If My.Settings.PrinterName.Length > 0 Then
    '            dlgPrint.PrinterSettings.PrinterName = My.Settings.PrinterName
    '        End If
    '        ' Display the print dialog.
    '        If dlgPrint.ShowDialog() = DialogResult.OK Then
    '            'If My.Settings.PrinterName Is Nothing Then
    '            '    My.Settings.PrinterName = New System.Drawing.Printing.PrintDocument
    '            'End If
    '            My.Settings.PrinterName = dlgPrint.PrinterSettings.PrinterName
    '            My.Settings.Save()
    '        End If
    '    Catch ex As Exception
    '        MsgBox(ex.Message)
    '    End Try

    'End Sub
    ' Make and return a PrintDocument object that's ready
    ' to print the paragraphs.
    Private Function PreparePrintDocument() As PrintDocument
        ' Make the PrintDocument object.
        Dim print_document As New PrintDocument

        ' Install the PrintPage event handler.
        AddHandler print_document.PrintPage, AddressOf Print_PrintPage

        ' Return the object.
        Return print_document
    End Function
    ' Print the next page.
    Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)

        Dim printfont As New Font("tahoma", 10)

        Dim linesPerPage As Single = 0
        linesPerPage = e.MarginBounds.Height / printfont.GetHeight(e.Graphics)
        ' There are no more pages.

        Dim installed_fonts As New System.Drawing.Text.InstalledFontCollection()

        ' Get an array of the system's font familiies.
        Dim font_families() As FontFamily = installed_fonts.Families()

        ' Display the font families.
        e.HasMorePages = True
        Dim t As Integer = 0
        Dim c As Integer = 0
        Dim l As Integer = 0
        For Each font_family As FontFamily In font_families
            'Console.Write(font_family.Name & ", ")
            If c = count And l < linesPerPage Then
                Try
                    e.Graphics.DrawString(font_family.Name, New Font(font_family.Name, 10), Brushes.Black, 0, t)
                Catch ex As Exception

                End Try

                t = t + 20
                count = count + 1
                l = l + 1

            End If
            c = c + 1
            If l >= linesPerPage Then Exit For
        Next font_family
        If count < font_families.Length Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If


    End Sub

    Private Sub TestPrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        ' Make a PrintDocument and attach it to 
        ' the PrintPreview dialog.
        dlgPrintPreview.Document = PreparePrintDocument()

        ' Preview.
        dlgPrintPreview.WindowState = FormWindowState.Maximized
        dlgPrintPreview.ShowDialog()
    End Sub

    Private Sub SetCouponToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetCouponToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgECoupon.ShowDialog()
        End If
    End Sub

    'Private Sub ListBar1_ItemClicked(ByVal sender As Object, ByVal e As vbAccelerator.Components.ListBarControl.ItemClickedEventArgs)
    '    Select Case UCase(e.Item.Caption)
    '        Case "NEW EMPLOYEE"
    '            dlgEmployee.setActionName("New")
    '            dlgEmployee.ShowDialog()
    '    End Select
    'End Sub


    'Private Sub ListBar1_SelectedGroupChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    '    Select Case UCase(ListBar1.SelectedGroup.Caption)
    '        Case "TRANSACTIONS"
    '            TabControl1.SelectedIndex = 0
    '        Case "COUPON"
    '            TabControl1.SelectedIndex = 1
    '    End Select

    'End Sub


    Private Sub LoginToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginToolStripMenuItem.Click
        Me.TransactionsToolStripMenuItem.Visible = False
        Me.ReportsToolStripMenuItem.Visible = False
        Me.AdmintratorToolStripMenuItem.Visible = False
        Me.AccessManagementToolStripMenuItem.Visible = False
        Me.HideToolStripMenuItem.Visible = False
        If Me.LoginToolStripMenuItem.Text = "Log&in" Then
            If LoginForm.ShowDialog = Windows.Forms.DialogResult.OK Then
                TransactionsToolStripMenuItem.Visible = True
                ReportsToolStripMenuItem.Visible = True
                AdmintratorToolStripMenuItem.Visible = True
                Me.HideToolStripMenuItem.Visible = True
                'MainMenu.Items("TransactionsToolStripMenuItem").Visible = LoginForm.login
                'MainMenu.Items("AdmintratorToolStripMenuItem").Visible = LoginForm.admin
                'MainMenu.Items("ReportsToolStripMenuItem").Visible = LoginForm.login
                AccessManagementToolStripMenuItem.Visible = LoginForm.admin
                MainMenu.Items("LoginToolStripMenuItem").Text = "Log&out"
                'MainMenu.Items("ReportsToolStripMenuItem").Visible = False
                'MainMenu.Items("QuarterToolStripMenuItem").Visible = False
                'MainMenu.Items("CouponMenuItem").Visible = False

            End If
        Else

            Me.LoginToolStripMenuItem.Text = "Log&in"
        End If
        
    End Sub


    Private Sub DishToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DishToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgDish.ShowDialog()
        End If
    End Sub

    Private Sub DailyMenuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DailyMenuToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgDailyMenu.ShowDialog()
        End If
    End Sub


    Private Sub OptionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionsToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgOptions.ShowDialog()
        End If
    End Sub

    Private Sub DepartmentToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DepartmentToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgDepartment.ShowDialog()
        End If
    End Sub

    Private Sub LocationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LocationToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgLocation.ShowDialog()
        End If
    End Sub

    Private Sub TypeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TypeToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgType.ShowDialog()
        End If
    End Sub

    Private Sub SetTotalOfDayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetTotalOfDayToolStripMenuItem.Click
        If Me.AdmintratorToolStripMenuItem.Visible Then
            dlgETotalOfDay.ShowDialog()
        End If
    End Sub



    Private Sub HideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HideToolStripMenuItem.Click

        'If LoginForm.confirm Then
        If Me.AdmintratorToolStripMenuItem.Visible = False Then
            If dlgCPass.ShowDialog = Windows.Forms.DialogResult.OK Then
                Me.AdmintratorToolStripMenuItem.Visible = True
                Me.HideToolStripMenuItem.Text = "&Lock"
            End If
        Else
            Me.AdmintratorToolStripMenuItem.Visible = False
            Me.HideToolStripMenuItem.Text = "&Unlock"
        End If
        'End If



    End Sub

    Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click
        dlgReport.ShowDialog()
    End Sub

    Private Sub DetailsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DetailsToolStripMenuItem.Click
        If dlgFindEmployee.ShowDialog() = Windows.Forms.DialogResult.OK Then
            dlgDetailReport.EmployeeID = dlgFindEmployee.employeeID
            dlgDetailReport.ShowDialog()
            
        End If

    End Sub
End Class
